package com.architecture.core.web.actions;

import com.architecture.core.web.vo.UserVO;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.stereotype.Controller;

/**
 * Created with IntelliJ IDEA.
 * LoginAction: Administrator
 * Date: 12-8-26
 * Time: 下午5:06
 * To change this template use File | Settings | File Templates.
 */
@Controller("userAction")
@Results({
        @Result(name = "create_success", location = "front/login.jsp"),
        @Result(name = "create_error", location = "front/login.jsp"),
        @Result(name = "update_success", location = "front/login.jsp"),
        @Result(name = "update_error", location = "front/login.jsp"),
        @Result(name = "active_success", location = "front/login.jsp"),
        @Result(name = "active_error", location = "front/login.jsp"),
        @Result(name = "delete_success", location = "front/login.jsp"),
        @Result(name = "delete_error", location = "front/login.jsp")
})
public class UserAction extends AbstractAction {

//    @Resource
//    private BaseUserService baseUserService;
//
//    @Resource
//    private BasePermissionService basePermissionService;

    private UserVO userVO = new UserVO();

    /**
     * A default implementation that does nothing an returns "success".
     * <p/>
     * Subclasses should override this method to provide their business logic.
     * <p/>
     * See also {@link com.opensymphony.xwork2.Action#execute()}.
     *
     * @return returns {@link #SUCCESS}
     * @throws Exception can be thrown by subclasses.
     */
    @Override
    @Action(value = "user")
    public String execute() {
        try {
            return super.execute();
        } catch (Exception ex) {

        }
        return null;
    }

//    @Action(value = "create_user")
//    public String createUser() {
//        try {
//
//            if (super.isAdmin()) {
//                this.baseUserService.createSonByFatherId((String) super.getSessionMap().get("currentId"), this.getUserVO().getUser());
//            } else {
//                this.baseUserService.createUser(this.getUserVO().getUser());
//            }
//            return super.CREATE_SUCCESS;
//        } catch (ErrException err) {
//            err.printStackTrace();
//            super.addActionError(err.getMessage());
//        }
//
//        return super.CREATE_ERROR;
//    }

//    @Action(value = "update_user")
//    public String updateUser() {
//
//        try {
//            if (super.isAdmin()) {
//                //判断用户是否有直接关联关系
//                if (!this.baseUserService.hasRelateUserOfId((String) super.getSessionMap().get("currentId"), this.getUserVO().getUser().getId())) {
//                    throw new ErrException(ErrCode.NO_RELATE);
//                }
//
//                this.baseUserService.updateUserByFatherId((String) super.getSessionMap().get("currentId"), this.getUserVO().getUser());
//            } else {
//                this.baseUserService.updateUser(this.getUserVO().getUser());
//            }
//            return super.UPDATE_SUCCESS;
//        } catch (ErrException err) {
//            err.printStackTrace();
//            super.addActionError(err.getMessage());
//        }
//
//        return super.UPDATE_ERROR;
//    }
//
//    @Action(value = "delete_user")
//    public String deleteUser() {
//
//        try {
//            if (!super.isAdmin()) {
//                throw new ErrException(ErrCode.NO_PERMISSION);
//            }
//            //判断用户是否有直接关联关系
//            if (!this.baseUserService.hasRelateUserOfId((String) super.getSessionMap().get("currentId"), this.getUserVO().getUser().getId())) {
//                throw new ErrException(ErrCode.NO_RELATE);
//            }
//
//            this.baseUserService.deleteSonOfIdByFatherId((String) super.getSessionMap().get("currentId"), this.getUserVO().getUser().getId());
//            return super.DELETE_SUCCESS;
//        } catch (ErrException err) {
//            err.printStackTrace();
//            super.addActionError(err.getMessage());
//        }
//
//        return super.DELETE_ERROR;
//    }
//
//    @Action(value = "active_user")
//    public String activeUser() {
//
//        try {
//
//            if (!super.isAdmin()) {
//                throw new ErrException(ErrCode.NO_PERMISSION);
//            }
//
//            //判断用户是否有直接关联关系
//            if (!this.baseUserService.hasRelateUserOfId((String) super.getSessionMap().get("currentId"), this.getUserVO().getUser().getId())) {
//                throw new ErrException(ErrCode.NO_RELATE);
//            }
//
//            this.baseUserService.activeUserByFatherId((String) super.getSessionMap().get("currentId"), this.getUserVO().getUser().getId(), true);
//            return super.ACTIVE_SUCCESS;
//
//        } catch (ErrException err) {
//            err.printStackTrace();
//            super.addActionError(err.getMessage());
//        }
//        return super.ACTIVE_ERROR;
//
//    }
//
//    @Action(value = "inactive_user")
//    public String inactiveUser() {
//
//        try {
//
//            if (!super.isAdmin()) {
//                throw new ErrException(ErrCode.NO_PERMISSION);
//            }
//
//            //判断用户是否有直接关联关系
//            if (!this.baseUserService.hasRelateUserOfId((String) super.getSessionMap().get("currentId"), this.getUserVO().getUser().getId())) {
//                throw new ErrException(ErrCode.NO_RELATE);
//            }
//
//            this.baseUserService.activeUserByFatherId((String) super.getSessionMap().get("currentId"), this.getUserVO().getUser().getId(), false);
//            return super.INACTIVE_SUCCESS;
//
//        } catch (ErrException err) {
//            err.printStackTrace();
//            super.addActionError(err.getMessage());
//        }
//        return super.INACTIVE_ERROR;
//
//    }

    public UserVO getUserVO() {
        return userVO;
    }

    public void setUserVO(UserVO userVO) {
        this.userVO = userVO;
    }

}
